import 'package:casdon/common/service/service_manager.dart';
import 'package:flutter/material.dart';

class ServiceProvider extends InheritedWidget {
  final ServiceManager serviceManager;

  const ServiceProvider({
    super.key,
    required this.serviceManager,
    required super.child,
  });

  static ServiceManager of(BuildContext context) {
    final provider = context.dependOnInheritedWidgetOfExactType<ServiceProvider>();
    if (provider == null) {
      throw Exception('ServiceProvider not found in widget tree');
    }
    return provider.serviceManager;
  }

  @override
  bool updateShouldNotify(ServiceProvider oldWidget) {
    return serviceManager != oldWidget.serviceManager;
  }
}